import {tryHideFullScreenLoading} from "./loading";
import messageErrorHint from './message-error-hint'

export function responseInterceptors(response) {
    const {status, data} = response;
    const {success, code = -1} = data;
    tryHideFullScreenLoading()
    if (status === 200) {
        let isSuccess = false;
        if (typeof success !== undefined && success) {
            isSuccess = true;
        } else if (typeof code !== undefined && code === 0) {
            isSuccess = true;
        }

        if (!isSuccess) {
            // error handle
            messageErrorHint(response, '服务器响应失败')
            return Promise.reject(response)
        }

        // success handle
        return response.data.data;

    } else {
        return Promise.reject(response)
    }
}


